/*
 * Copyright (C) 2013 Apple Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#ifndef AccessibilityDelegate_h
#define AccessibilityDelegate_h

#include "WebKit.h"
#ifdef _WEBKIT_NEW
#include "StompCommand.h"
#endif

class CWebkitView;
class CSKEYBid;
class AccessibilityDelegate : public IAccessibilityDelegate
{
public:
    AccessibilityDelegate(CWebkitView * owner) : m_refCount(0), m_owner(owner) { }
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override;
    ULONG STDMETHODCALLTYPE AddRef(void) override;
    ULONG STDMETHODCALLTYPE Release(void) override;

    HRESULT STDMETHODCALLTYPE fireFrameLoadStartedEvents() override;
    HRESULT STDMETHODCALLTYPE fireFrameLoadFinishedEvents() override;

#ifdef _WEBKIT_NEW
	HRESULT STDMETHODCALLTYPE didWebSocketConnect(unsigned long identifier, UINT_PTR nativeHandle) override;
	HRESULT STDMETHODCALLTYPE didWebSocketReceiveMessage(unsigned long identifier, BSTR *message) override;
	HRESULT STDMETHODCALLTYPE didWebSocketReceiveBinaryData(unsigned long identifier, unsigned char **data, int *dataLength) override;
	HRESULT STDMETHODCALLTYPE didWebSocketReceiveMessageError(unsigned long identifier) override;
	HRESULT STDMETHODCALLTYPE didWebSocketStartClosingHandshake(unsigned long identifier) override;
	HRESULT STDMETHODCALLTYPE didWebSocketClose(unsigned long identifier, unsigned short code, BSTR reason) override;
	HRESULT STDMETHODCALLTYPE didWebSocketUpgradeURL(unsigned long identifier) override;
	HRESULT STDMETHODCALLTYPE willWebSocketSendFrame(unsigned long identifier, UINT opcode, unsigned char **data, int *dataLength) override;
	HRESULT STDMETHODCALLTYPE didWebSocketSendFrame(unsigned long identifier, UINT opcode, const unsigned char *data, int dataLength) override;
	HRESULT STDMETHODCALLTYPE didStorageClear(UINT storageType);
	HRESULT STDMETHODCALLTYPE didStorageManipulateKey(UINT storageType, BSTR *key);
	HRESULT STDMETHODCALLTYPE didStorageManipulateValue(UINT storageType, BSTR key, BSTR *value);
#endif
protected:
	CSKEYBid *getMain() const;

	CWebkitView *m_owner;
#ifdef _WEBKIT_NEW
	void addUnknownMsg(UINT opcode, const unsigned char *data, int dataLength, CStompCommand::Command cmdType, intptr_t pos);
	void addUnknownMsg(BSTR message);
	void addUnknownMsg(const unsigned char *data, int dataLength, CStompCommand::Command cmdType, intptr_t pos);
	void addUnknownMsg(LPCWSTR unknownCmd);

	intptr_t lastRequest;
	SYSTEMTIME tmBid, tmDeal;
	wchar_t bidtime[40], dealtime[40];	//recv 2-2/2-3
#endif
private:
	ULONG m_refCount;
};

#endif
